Skip to content

test(state): add unit tests for state accessors#3752

Open
Ehsan-saradar wants to merge 5 commits into
NethermindEth:mainfrom
Ehsan-saradar:test/state-accessors-tests
Open

test(state): add unit tests for state accessors#3752
Ehsan-saradar wants to merge 5 commits into
NethermindEth:mainfrom
Ehsan-saradar:test/state-accessors-tests

Conversation

@Ehsan-saradar

Copy link
Copy Markdown
Contributor

Description

Adds dedicated unit tests for core/state/accessors.go, which previously had no direct coverage.

Covers:

  • Contract accessors (Has/Get/Write/DeleteContract): absence before write, write→read round-trip, overwrite, and delete.
  • Class accessors (Has/Get/Write/DeleteClass): same lifecycle, round-tripping an encoded Sierra class definition.
  • History accessors (nonce / class-hash / storage): writing and deleting history entries, read back through StateReader — reading at the written block, stepping back to the previous entry, returning zero before the first entry, and honouring block boundaries across two entries.
  • GetStateObject: not-found propagation and successful wrapping of a stored contract.

Issue

Closes #3688

Type of change

  • Tests

Testing

go test ./core/state/ passes locally.

Copilot AI review requested due to automatic review settings June 22, 2026 08:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds dedicated unit tests for core/state/accessors.go to address missing direct coverage (Issue #3688), validating basic CRUD behavior for contracts/classes and correctness of history accessors when read through StateReader.

Changes:

  • Adds unit tests for contract and class accessors (Has/Get/Write/Delete*).
  • Adds tests for nonce/class-hash/storage history accessors using StateReader historical reads.
  • Adds tests for GetStateObject not-found propagation and success wrapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/state/accessors_test.go
Comment thread core/state/accessors_test.go
Comment thread core/state/accessors_test.go
@Ehsan-saradar Ehsan-saradar force-pushed the test/state-accessors-tests branch from c13deef to 24e1f7f Compare June 22, 2026 11:59
@rodrodros

rodrodros commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Closing PR, 3 days old and comments unanswered

My mistake, were address but not answered

@rodrodros rodrodros closed this Jun 25, 2026
@rodrodros rodrodros reopened this Jun 25, 2026
@Ehsan-saradar

Copy link
Copy Markdown
Contributor Author

@rodrodros all comments are fixed

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.36%. Comparing base (682a0d2) to head (270cd94).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3752      +/-   ##
==========================================
+ Coverage   75.03%   76.36%   +1.33%     
==========================================
  Files         433      433              
  Lines       38594    38631      +37     
==========================================
+ Hits        28960    29502     +542     
+ Misses       7632     7062     -570     
- Partials     2002     2067      +65     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread core/state/accessors_test.go Outdated
Comment thread core/state/accessors_test.go Outdated
Comment thread core/state/accessors_test.go
Adds dedicated unit tests for core/state/accessors.go.

Closes NethermindEth#3688
Give each subtest its own StateDB (and StateReader for history) so they
no longer share mutable state or depend on execution order. Rename the
contract-writing helper to storeContract to avoid shadowing the
package-level writeContract function.
@RafaelGranza RafaelGranza force-pushed the test/state-accessors-tests branch from 6a35f50 to b2230fa Compare June 26, 2026 11:27
Move accessors_test.go to package state_test so it compiles against the
exported accessors only, instead of reaching into unexported internals
(stateDB.disk, newTestStateDB). Contract/class tests now write through a
plain memory store, and history tests build a StateDB/StateReader via the
exported constructors.

Drop the "wraps the stored contract on success" case from TestGetStateObject:
it only asserted, via unexported fields, that the constructor copied its
inputs (a tautological test). The not-found case, which is the actual
behavior of GetStateObject, is kept.
@Ehsan-saradar Ehsan-saradar force-pushed the test/state-accessors-tests branch from b74eedb to 365cedf Compare June 27, 2026 05:44
@RafaelGranza

Copy link
Copy Markdown
Contributor

@Ehsan-saradar, please fix the lint errors.
You can run them locally with make lint

@Ehsan-saradar

Copy link
Copy Markdown
Contributor Author

Hey @RafaelGranza, fixed the lint error in dca0afe (the long line). Ran make lint locally and it's clean now. Could you re-approve the CI run when you get a chance? Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread core/state/accessors_test.go
Comment thread core/state/accessors_test.go
@RafaelGranza RafaelGranza force-pushed the test/state-accessors-tests branch from dca0afe to eb9787a Compare June 29, 2026 11:27

@RafaelGranza RafaelGranza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at the copilot comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread core/state/accessors_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The new state accessors have no dedicated unit tests

4 participants